import 'package:json_annotation/json_annotation.dart';

part 'history_item.g.dart';

@JsonSerializable()
class HistoryItem {
  @JsonKey(name: 'post_id', defaultValue: '')
  final String postId;

  @JsonKey(defaultValue: '')
  final String title;

  @JsonKey(defaultValue: '')
  final String preview;

  @JsonKey(name: 'view_time', defaultValue: 0)
  final int viewTime;

  HistoryItem({
    this.postId = '',
    this.title = '',
    this.preview = '',
    this.viewTime = 0,
  });

  factory HistoryItem.fromJson(Map<String, dynamic> json) =>
      _$HistoryItemFromJson(json);

  Map<String, dynamic> toJson() => _$HistoryItemToJson(this);

  @override
  String toString() {
    return 'HistoryItem(postId: $postId, title: $title, preview: $preview, viewTime: $viewTime)';
  }
}